unit Form_ViewData;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, RzButton, ExtCtrls, RzPanel, Grids, DBGrids, DB, MemDS,
  DBAccess, Uni,UniConnct,FormEx_View, StdCtrls, Mask, RzEdit;

type
  TFormViewDATA = class(TFormExView)
    DataSource1: TDataSource;
    dbgrd1: TDBGrid;
    Tool_1: TRzToolbar;
    Btnx_2: TRzToolButton;
    ImageList1: TImageList;
    UniQuery1: TUniQuery;
    Edit_TABL: TRzEdit;
    rzspcr1: TRzSpacer;
    procedure Btnx_2Click(Sender: TObject);
  private
    FUniConnct:TUniConnection;
    FTablName :string;
  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
  end;

var
  FormViewDATA: TFormViewDATA;

function ViewViewDATA(ATablName:string):Integer;  

implementation

uses
  Class_AppUtil;

{$R *.dfm}

function ViewViewDATA(ATablName:string):Integer;
begin
  try
    FormViewDATA:=TFormViewDATA.Create(nil);
    FormViewDATA.FTablName:=ATablName;
    Result:=FormViewDATA.ShowModal;
  finally
    FreeAndNil(FormViewDATA);
  end;
end;
                  
procedure TFormViewDATA.Btnx_2Click(Sender: TObject);
begin
  ModalResult:=mrCancel;
end;

procedure TFormViewDATA.SetComboItems;
begin
  inherited;

end;

procedure TFormViewDATA.SetCommParams;
begin
  inherited;
  Caption:='VIEWDATA';

  Edit_TABL.Text:=FTablName;
end;

procedure TFormViewDATA.SetGridParams;
begin
  inherited;

end;

procedure TFormViewDATA.SetInitialize;
var
  I:Integer;
  SQLA:string;
begin
  inherited;
  try
    FUniConnct:=UniConnctEx.GetConnection(CONST_MARK_DATA);
    //-<
    //->
  finally
  end;

  if FUniConnct<>nil then
  begin
    SQLA:='SELECT TOP 100 * FROM [%S]';
    SQLA:=Format(SQLA,[FTablName]);


    if UniQuery1.Active then
    begin
      UniQuery1.Active:=False;
    end;

    UniQuery1.SQL.Clear;
    UniQuery1.SQL.Add(SQLA);
    UniQuery1.Connection:=FUniConnct;
    UniQuery1.Open;

    for I:=0 to dbgrd1.Columns.Count-1 do
    begin
      dbgrd1.Columns.Items[I].Width:=120;
    end;
  end;
end;

procedure TFormViewDATA.TryFreeAndNil;
begin
  inherited;
  if UniQuery1.Active then
  begin
    UniQuery1.Active:=False;
  end;
  
  if FUniConnct<>nil then
  begin
    FreeAndNil(FUniConnct);
  end;
end;

end.
